package jd.client.xml;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * @author Denis Migol
 * 
 */
public abstract class SAXResponseParser<E> extends DefaultHandler implements ResponseParser<E> {

	protected E entity;

	@Override
	public E parse(final String xml) {
		entity = null;
		try {
			final SAXParserFactory factory = SAXParserFactory.newInstance();
			final SAXParser saxParser = factory.newSAXParser();
			saxParser.parse(new ByteArrayInputStream(xml.getBytes()), this);
		} catch (final ParserConfigurationException e) {
		} catch (final SAXException e) {
		} catch (final IOException e) {
		}
		return entity;
	}
}
